<script type="text/javascript">
	$("li#menu4").addClass("current");
</script>
<form action="" method="post">
	<table>
		<tr>
			<td>Libell&eacute;:</td>
			<td><input type="text" name="libelle" value="<?php echo $libelle; ?>"/></td>
		</tr>
		<tr>
			<td>Cat&eacute;gories principales:</td>
			<td>
				<select name="catParent">
					<option value="0">Cat&eacute;gorie parente<option>
				<?php
					$idCatParent=isset($idCatParent)?$idCatParent:null;
					foreach($mainCategories as $mainCat)
					{
						if($idCatParent==$mainCat->getIdCat())
							echo "<option value='".$mainCat->getIdCat()."' selected='selected'>".$mainCat->getNameCat()."</option>";
						else
							echo "<option value='".$mainCat->getIdCat()."'>".$mainCat->getNameCat()."</option>";
							
					}			
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td><input type="submit" value="<?php echo $bouton=isset($_POST['edit'])?"Editer":"Cr&eacute;er"; ?> "/></td>
		</tr>
		<?php 
			if(isset($_POST['edit']))
				echo "<input type='hidden' name='idEdit' value=".$_POST['idCat']."/>";
		?>
	</table>	
</form>

<hr>

<table>		

<?php
foreach($mainCategories as $mainCat)
{
?>
	<form method='post' action=''>
		<tr>
			<td><?php echo  $mainCat->getNameCat() ?></td>
			<td><input type="submit" value="Editer" name="edit"></td>
			<td><input type="submit" value="Supprimer" name="delete"></td>
		</tr>
		<input type="hidden" name="idCat" value="<?php echo $mainCat->getIdCat()?>"/>
	</form>

	<table>		
	
		<?php
		$subcategories = Category::listing('WHERE CAT_IdParent ='.$mainCat->getIdCat().' ORDER BY CAT_Libelle');
		if(! 0 == $subcategories)
		{
			foreach($subcategories as $subCat)
			{
			?>	
				<form method='post' action=''>
					<tr>
						<td><?php echo '-------    '. $subCat->getNameCat()?></td>
						<td><input type="submit" value="Editer" name="edit"></td>
						<td><input type="submit" value="Supprimer" name="delete"></td>
					</tr>
					<input type="hidden" name="idCat" value="<?php echo $subCat->getIdCat()?>"/>
				</form>
			<?php
			}
		}
		
	echo "</table><br/><br/>";
	
}
	
echo "</table>";

			
	

?>